<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	public function __construct(){
        parent::__construct();
        
    }
    
	public function index()
	{
		$this->load->view('index');
	}
	public function test(){
		$post_data = array();
		$post_data['code'] = $this->input->post('code');
		$post_data['mobile']  = $this->input->post('mobile');
		$post_data['content']  = $this->input->post('content');
		$post_data['time']  = $this->input->post('time');
		log_message('info', '======post data:'.json_encode($post_data));
	}
	
	public function readFile(){
		$this->load->helper('file');
		/*
		$file_handle = fopen("d:/ns.json", "r");
		while (!feof($file_handle)) {
		   $line = fgets($file_handle);
		   if($line){
		   	  //$json = json_decode($line);
		   	  log_message('info','id->'.$line);
		   }
		   //echo $line;
		}
		fclose($file_handle);
		*/
		$file_cnt = read_file('d:/ns.json');
		$json = json_decode($file_cnt,true);
		
		$len = count($json);
		log_message('info','record is '.$len);
		
		foreach ( $json as  $record) {
       		log_message('info','id->'.$record['_id'].' title->'.(array_key_exists('title',$record)? $record['title'] : ''));
       		// $record 中还有 content (array_key_exists('content',$record)? $record['content'] : '')
		}
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */